<template>
  <div id='earlyWarning'>
    <el-carousel :interval="5000" :indicator-position="'none'" arrow="always">
      <el-carousel-item v-for="(item,index) in data" :key="index">
        <div class="box">
          <div class="box-head">
            <div
              :style="`background: ${item.type == '地震预警' ? '#ffcf40;' : 'rgba(24, 144, 255, 0.7)'}`">
              <span>{{item.type}}</span>
            </div>
            <div>
              <i class="el-icon-location-outline"></i>
              <span>{{item.distance}}km</span>
            </div>
          </div>
          <div class="box-title">
            <span>{{item.formattedAddress}}</span>
          </div>
          <div class="box-log">
            <span>纬度</span>
            <span>{{item.epiLat}}</span>
            <span>经度</span>
            <span>{{item.epiLon}}</span>
          </div>
          <div class="box-date">
            <span>{{item.oriTime}}</span>
          </div>
          <div class="box-level">
            <span>{{item.magnitude}}</span>
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
import { getHomeAlarm } from '@/api/api.js';
import { mapGetters } from 'vuex';

export default {
  name: 'earlyWarning',
  components: {},
  data() {
    return {
      data: [
        // {
        //   level: '3.1',
        //   type: '预警',
        //   scene: '云南大理州大理市',
        //   time: '2022-04-21 16:18:44',
        //   latitude: '25.55°',
        //   longitude: '100.05°',
        //   depth: '11.0',
        // },
        // {
        //   level: '3.1',
        //   type: '预警',
        //   scene: '台湾屏东县海域',
        //   time: '2022-04-21 07:36:11',
        //   latitude: '25.55°',
        //   longitude: '100.05°',
        //   depth: '10.0',
        // },
        // {
        //   level: '3.1',
        //   type: '预警',
        //   scene: '新疆吐鲁番托克…',
        //   time: '2022-04-21 23:58:22',
        //   latitude: '25.55°',
        //   longitude: '100.05°',
        //   depth: '10.0',
        // },
      ],
      timer: null,
    };
  },
  computed: {},
  created() {
    // if (process.client){}
  },
  deactivated() {
    clearTimeout(this.timer);
  },
  beforeDestroy() {
    clearTimeout(this.timer);
  },
  mounted() {
    this.$nextTick(() => {
      this.getList();
      this.timer = setTimeout(() => {
        this.getList();
      }, 2000);
    });
  },
  beforeCreate() {},
  beforeMount() {},
  methods: {
    async getList() {
      const location = encodeURIComponent(this.location);
      const res = await getHomeAlarm({
        address: location,
        sysKey: 'zzyearthquakewarning',
      });
      if (res.code == 200) {
        this.data = res.data;
      }
    },
  },
  computed: {
    ...mapGetters(['location']),
  },
};
</script>
<style lang='scss' scoped>
#earlyWarning {
  width: 100%;
  height: 100%;
}
.seamless-warp {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.box {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: rgba(250, 219, 20, 0.3);
  border-radius: 4px;
  padding: 16px;
  font-size: 14px;
  .box-head {
    display: flex;
    justify-content: space-between;
    > div {
      line-height: 24px;
      &:nth-child(1) {
        // width: 56px;
        padding: 1px 5px;
        // height: 24px;
        text-align: center;
        background: #ffcf40;
        border-radius: 4px;
      }
      &:nth-child(2) {
        color: rgba(0, 0, 0, 0.65);
      }
    }
  }
  .box-title {
    margin: 16px 0;
    font-weight: bold;
    max-height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .box-log {
    white-space: nowrap;
    > span {
      margin-right: 6px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: rgba(0, 0, 0, 0.65);
    }
  }
  .box-date {
    margin-top: 12px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.65);
  }
  .box-level {
    position: absolute;
    right: 0%;
    bottom: 0%;
    font-size: 39px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.3);
    text-indent: 53px;
    width: 90px;
    height: 90px;
    line-height: 145px;
    background: url('../../assets/images/circle.png') no-repeat no-repeat 0px
      10px;
  }
}
::v-deep .el-carousel {
  height: 100%;
}
::v-deep .el-carousel__container {
  height: 100%;
}

::v-deep .el-carousel__arrow--left {
  display: none;
}

::v-deep .el-carousel__arrow--right {
  display: none;
}
</style>